var net = require('net');


var sock = net.connect({
    port:6080,
    host:"127.0.0.1",
},function(){
    console.log('========connected to server===========');
})

sock.on('connect',function(){
    console.log('connect success!');

    sock.write("HelloWorld!", "utf8");
})

sock.on('data',function(data){
    console.log('=======data========',data);
    //data 是 Buffer

    const stringValue = data.toString('utf8', 0, data.length);
    console.log('====stringValue======',stringValue)
    var buf = Buffer.from(data);
    console.log('====buf======',buf)

})

sock.on("end",function(){
    console.log('=====end========')
})

sock.on("close",function(){
    console.log('=====close========')
})

sock.on('error',function(err){
    console.log('========error========',err);
})